package service.state;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.Statement;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

import service.CommonServlet;

public class AddState extends CommonServlet {
	
	@Override
	protected void execute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try
		{
			String sContent = request.getParameter("content");
			if(sContent==null) throw new Exception("sContent cann't be empty");
			String sql = "insert into state_mess values (null, ?, curdate(), null, ? )";
			PreparedStatement pstmt = mConnection.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
			pstmt.setString(1, sContent);
			pstmt.setInt(2, uNo);
			pstmt.executeUpdate();
			ResultSet rs = pstmt.getGeneratedKeys();
			rs.next();
			response.getWriter().println(rs.getInt(1));
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * Constructor of the object.
	 */
	public AddState() {
		super();
	}

}
